package com.example.wendao.model.service;

import androidx.lifecycle.LiveData;
import androidx.paging.DataSource;
import androidx.room.Query;

import com.example.wendao.model.db.dao.UserDao;
import com.example.wendao.model.db.database.AppDatabase;
import com.example.wendao.model.entity.NewsComment;
import com.example.wendao.model.entity.User;


public class UserService {

    private UserDao userDao;

    public UserService(){
        userDao = AppDatabase.getDatabases().getUserDao();
    }

    //根据用户id查找用户
    public User findUserById(int id){
        return userDao.findUserById(id);
    }

    //根据用户名模糊查找用户
    public DataSource.Factory<Integer, User> findUserByName(String username){
        return userDao.findUserByName(username);
    }

    public DataSource.Factory<Integer, User> queryAllUser() {
        return userDao.queryAllUser();
    }

    //添加用户（User[]  要插入的用户列表）   成功返回1
    public int insertUser(User[] users) {
         userDao.insertUser(users);
         return 1;
    }

    public int delUser(User user) {
        userDao.delUser(user);
        return 1;
    }

    public int findUserName(String username){
        if(userDao.findUserName(username)!=null){
            return 1;
        }
        return 0;
    }

    public void updateUser(User user) {
        userDao.updateUser(user);
    }


    public void register(User user){
        userDao.register(user);
    }

    public User login(String username,String password){
        return userDao.login(username, password);
    }

    //根据多个id查询用户列表
    public DataSource.Factory<Integer, User> findSomeUsersByUserIds(String userids){return userDao.findSomeUsersByUserIds(userids);}


}
